來談談看 API Gateway
建立一個連接原本 API 服務的 API Gateway
建立客製化 error response
Response Body Mapping Template →
{
"error": "maintenance mode"
}
建立 resource policy
我們會拒絕 "192.168.1.0/24", "10.0.0.0/16" 來的流量,如此他們就會看到特定回應
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "execute-api:/{{stageNameOrWildcard}}/{{httpVerbOrWildcard}}/{{resourcePathOrWildcard}}",
"Condition" : {
"IpAddress": {
"aws:SourceIp": [ "192.168.1.0/24", "10.0.0.0/16" ]
}
}
},
{
"Effect": "Deny",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "execute-api:/{{stageNameOrWildcard}}/{{httpVerbOrWildcard}}/{{resourcePathOrWildcard}}"
}
]
}
調整 Route 53 的設定 → 原本是直接 ALB,改成先到 api gateway
相較起 WAF,設定變得麻煩許多。但後續維運方便很多,改動 resource 幅度也小很多(改 WAF rule v.s. 改 DNS record )。而且幾乎可算是 2 塊美金可解決(maintenance mode 時才會使用)